const pool = require('./db.js')
class solidDao{
  // 根据农田的id获取病虫害的数据
  async getSolidData(id){
    try{
      let result = await pool.execute('select * from soliddata where farmland_id=?',[id])
      return result
    }catch(err){
      console.log("出错："+err)
    }
  }
    // 添加土壤数据
    async addSolidData(farmland_id,moisture,ph,nitrogen,phosphorus,potassium,organic_matter,temperature,salinity,time){
      try{
        let result = pool.execute('insert soliddata(farmland_id,moisture,ph,nitrogen,phosphorus,potassium,organic_matter,temperature,salinity,timestamp) values(?,?,?,?,?,?,?,?,?,?) ',[farmland_id,moisture,ph,nitrogen,phosphorus,potassium,organic_matter,temperature,salinity,time])
        return result
      }catch(err){
        console.log("出错："+err)
      }
    }
    // 修改土壤数据
    async modifyPestData(id,farmland_id,moisture,ph,nitrogen,phosphorus,potassium,organic_matter,temperature,salinity,time){
      try{
        let result = pool.execute('update soliddata set farmland_id=?,moisture=?,ph=?,nitrogen=?,phosphorus=?,potassium=?,organic_matter=?,temperature=?,salinity=?,timestamp=? where solid_id=?',[farmland_id,moisture,ph,nitrogen,phosphorus,potassium,organic_matter,temperature,salinity,time,id])
        return result
      }catch(err){
        console.log("出错："+err)
      }
    }
    // 删除土壤数据
    async deleteSolidData(id){
      try{
        let result = pool.execute('delete from soliddata where solid_id=?',[id])
        return result
      }catch(err){
        console.log("出错："+err)
      }
    }
}

module.exports = new solidDao()